//
//  CRTextView.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/24.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRTextView.h"

@interface CRTextView ()

/**
 *  提醒文字
 */
@property (nonatomic, strong) UILabel *placeHolder;

@end
@implementation CRTextView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.placeHolder = [[UILabel alloc] init];
        self.placeHolder.text = @"请输入内容...";
        self.font = [UIFont systemFontOfSize:18];
        self.placeHolder.font = self.font;
        self.placeHolder.textColor = [UIColor lightGrayColor];
        [self addSubview:self.placeHolder];
        [self becomeFirstResponder];
        // 监听textView文字的改变通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextViewTextDidChangeNotification object:nil];
        
    }
    return self;
}

- (void)setText:(NSString *)text
{
    [super setText:text];
    [self textChange];

    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.placeHolder.frame = CGRectMake(6, 0, 150, 30);
    
}

- (void)textChange
{
    self.placeHolder.hidden = (self.text.length != 0);
}

// 移除监听通知
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

// 给内部的textfile赋值
- (void)setPlaceHolderString:(NSString *)placeHolderString
{
    self.placeHolder.text = placeHolderString;
}

@end














